<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\Admin\Qh_NoticeRequest;
use App\Models\Qh_Notice;
use Illuminate\Http\JsonResponse;

class Qh_NoticeController extends AdminBaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return JsonResponse|object
     */
    public function index()
    {
        $list = Qh_Notice::filter(\request()->all())->orderByDesc('id')->paginate(\request('perPage', 10));
        return $this->restful($list);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param Qh_NoticeRequest $request
     * @return JsonResponse|object
     */
    public function store(Qh_NoticeRequest $request)
    {
        $params = $request->validated();

        $notice = Qh_Notice::create($params);

        return $this->restful($notice);
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     * @return JsonResponse|object
     */
    public function show(int $id)
    {
        return $this->restful();
    }

    /**
     * Update the specified resource in storage.
     *
     * @param Qh_NoticeRequest $request
     * @param int $id
     * @return JsonResponse|object
     */
    public function update(Qh_NoticeRequest $request, int $id)
    {
        $params = $request->validated();

        $result = Qh_Notice::where('id', $id)->update($params);

        return $this->restful($result);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     * @return JsonResponse|object
     */
    public function destroy(int $id)
    {
        $result = Qh_Notice::where('id', $id)->delete();

        return $this->restful($result);
    }
}
